<script setup lang="ts" name="ConsultList">
import ConsultItem from './consult-item.vue'
import { ref } from 'vue'
import type { ConsultType } from '@/enums'
import type { ConsultOrderItem } from '@/types/consult'
import { getConsultOrderList } from '@/api/consult'
const props = defineProps<{ type: ConsultType }>()
const list = ref<ConsultOrderItem[]>([])
const loading = ref(false)
const finished = ref(false)

// 查询参数
const params = {
  type: props.type,
  current: 1,
  pageSize: 10
}
const onLoad = async () => {
  const res = await getConsultOrderList(params)
  list.value.push(...res.data.rows)

  if (list.value.length < res.data.total) {
    params.current++
  } else {
    finished.value = true
  }

  loading.value = false
}
</script>

<template>
  <div class="consult-list">
    <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多数据啦"
      @load="onLoad"
    >
      <consult-item v-for="item in list" :key="item.id" :item="item" />
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.consult-list {
  padding: 10px 15px;
}
</style>
